var fun={
    rand(min,max){
        return Math.round(Math.random()*(max-min))+min;
    },
    array_rand(arr){
        arr.sort(()=>{
            return Math.random()-0.5;
        })
    },
    two(num){
		var str=num.toString();
		return str.length<2?'0'+str:str;
    },
	today(){
        return this.date();
    },
    ios_date_format(value) {
        if (typeof value === 'string') {
            value = value.replace(/-/g, '/')
        }
        return value
    },
	date(timestamp=0,type='date'){
		var date=timestamp>0?new Date(timestamp):new Date();
		const year = date.getFullYear()
		const month = date.getMonth() + 1
		const day = date.getDate()
		var date_str=`${[year, month, day].map(this.two).join('-')}`;
		if(type=="date"){
			return date_str;
		}
		const hour = date.getHours()
		const minute = date.getMinutes()
		const second = date.getSeconds();
        if(type=="json"){
            return {
                year,
                month,
                day,
                hour,
                minute,
                second,
            }
        }
		var time_str=`${[hour, minute, second].map(this.two).join(':')}`;
		return date_str+" "+time_str;
	},
    cache(k,v,expire){
        if(!k) return "";
        k="tansuo19-gitee-page-"+k;
        let o=localStorage;
        let now=new Date().getTime();
        if(v===undefined){
            let re=o.getItem(k);
            try{
                re=JSON.parse(re);
            }catch(e){
                console.log(e);
            }
            if( !re || (re['expire']>0 && re['expire']<now) ) return null;
            return re['value'];
        }
        if(v===null){
            o.removeItem(k);
            return "";
        }
        let data={
            expire:expire && expire>0?new Date().getTime()+expire*1000:0,
            value:v,
        }
        o.setItem(k,JSON.stringify(data));
        return "";
    }
}